#include<vector>
using namespace std;

class Solution {
public:
    void sortColors(vector<int>& nums) {
        int first = 0, second = 0, third = 0;
        while (third < nums.size()) {
            switch (nums[third]) {
            case 0:
                if (first != third) 
                    swap(nums[first], nums[third]);
                else {
                    ++second;
                    ++third;
                }
                ++first;
                if (first > second)
                    ++second;
                break;
            case 1:
                if (second != third)
                    swap(nums[second], nums[third]);
                ++second;
            default:
                ++third;
            }
        }
    }
};

int main() {
    Solution sol;
    vector<int>nums = { 2,0,2,1,1,0 };
    sol.sortColors(nums);
}